package de.fhd.pms.ctrl;

import org.apache.log4j.Logger;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import de.fhd.pms.ctrl.KundeController;
import de.fhd.pms.dao.KundeDao;
import de.fhd.pms.model.Kunde;

public class KundeController {
	private static Logger log = Logger.getLogger(KundeController.class);
	private KundeDao kundeDao = null;

	public void setKundenDao(KundeDao kundeDao) {
		this.kundeDao = kundeDao;
	}

	/**
	 * 
	 * <p>Creates new {@link Kunde}.</p>
	 * <p>Expected HTTP Get and request '/KundenAnlegen.html'.</p>
	 * @param id primary key of the customer
	 * 
	 */
	@RequestMapping(value = "/kundenreg.html", method = RequestMethod.GET)
	public ModelAndView edit1(@RequestParam(required = false) Integer kundennummer) {
		log.debug("kundenreg.html");
		ModelAndView mv = new ModelAndView();
		if (kundennummer == null) {
			mv.addObject(new Kunde());
		} 
//		else {
//			mv.addObject(kundeDao.findById(kundennummer));
//		}
		mv.setViewName("Kundenregistrierung");
		return mv;
	}
	
	/**
	 * 
	 * <p>Edits {@link Kunde}.</p>
	 * <p>Expected HTTP Get and request '/KundenBearbeiten.html'.</p>
	 * @param id primary key of the customer
	 * 
	 */
	@RequestMapping(value = "/kundebearbeiten.html", method = RequestMethod.GET)
	public ModelAndView edit2(@RequestParam(required = true) Integer kundennummer) {
		log.debug("kundebearbeiten.html");
		ModelAndView mv = new ModelAndView();
		if (kundennummer == null) {
			mv.addObject(new Kunde());
		} 
//		else {
//			mv.addObject(kundeDao.findById(kundennummer));
//		}
		mv.setViewName("kundebearbeiten");
		return mv;
	}

//	/**
//	 * 
//	 * <p>Saves {@link Kunden} in the database.</p>
//	 * <p>Expected HTTP POST and request '/SpeichereDvd.html'.</p>
//	 * @return a redirect to page '/index.html' - homepage for customers
//	 *
//	 */
//	@RequestMapping(value = "/speicherekunden.html", method = RequestMethod.POST)
//	public String save(Kunde kunde, Model model) {
//		kundeDao.save(kunde);
//		return "redirect:index.html";
//	}
	
}
